package org.example.testone.common;


import org.example.testone.constant.HttpStatusCode;

/**
 * @Author: MoChen
 * @Description: 通用返回结果
 * @Date: 2022/3/11 14:13
 */

public class Result {

    private Integer status;
    private String message;
    private Object data;

    public Integer getStatus() {
        return status;
    }

    public Result setStatus(Integer status) {
        this.status = status;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Result setMessage(String message) {
        this.message = message;
        return this;
    }

    public Object getData() {
        return data;
    }

    public Result setData(Object data) {
        this.data = data;
        return this;
    }

    public Result(Integer status, String message, Object data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public Result(Integer status, String message) {
        this.status = status;
        this.message = message;
    }

    public Result(String message) {
        this.message = message;
    }

    public static Result success(Object data) {
        return new Result(HttpStatusCode.OK.getCode(), HttpStatusCode.OK.getMessage(), data);
    }

    public static Result success() {
        return new Result(HttpStatusCode.OK.getCode(), HttpStatusCode.OK.getMessage(), null);
    }

    public static Result error(Object data) {
        return new Result(HttpStatusCode.SERVER_ERROR.getCode(), HttpStatusCode.SERVER_ERROR.getMessage(), data);
    }

    public static Result error() {
        return new Result(HttpStatusCode.SERVER_ERROR.getCode(), HttpStatusCode.SERVER_ERROR.getMessage(), null);
    }

}
